package org.guajava.controller.system;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.guajava.common.config.Global;
import org.guajava.domain.SysMenu;
import org.guajava.domain.SysUser;
import org.guajava.framework.web.base.BaseController;
import org.guajava.service.ISysMenuService;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页 业务处理
 * 
 * @author yuewei
 */
@Controller
public class SysIndexController extends BaseController
{
    @Autowired
    private ISysMenuService menuService;

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap) {
        // 取身份信息
        SysUser user = getSysUser();
        /* List<SysMenu> menus = menuService.selectMenusByUser(user);  */
        List<SysMenu> topDirectoryList = new ArrayList<SysMenu>();
        List<SysMenu> MenuList = menuService.selectMenusByUser(user);  //获取当前用户下的菜单集合
        for (SysMenu menuAll : MenuList) {
            if (menuAll.getParentId() == 0) {
                topDirectoryList.add(menuAll);
            }
        }
        mmap.put("topDirectoryList", topDirectoryList);
        mmap.put("user", user);
        mmap.put("copyrightYear", Global.getCopyrightYear());
        return "index";
    }

    // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap)
    {
        mmap.put("version", Global.getVersion());
        return "main";
    }
}
